import time
import datetime
from python_baway.common.xcommon import xcheck, sep

sep('timestamp')
t = time.time()
xcheck(t, 't')
DT = 3600 * 24 * 365
print(t / DT)
print(time.ctime(t))

sep('struct_time')
st = time.localtime()
xcheck(st, 'st localtime()')
gmst = time.gmtime()
xcheck(gmst, 'gmst')
print(time.strftime('%Y-%m-%d %H:%M:%S', st))
print(time.asctime(st))
st2 = time.localtime(t)
print(time.asctime(st2))
gmst2 = time.gmtime(t)
print(time.asctime(gmst2))

sep('datetime and timestamp')
one_day_earlier_delta = datetime.timedelta(days=-1)
today_datetime = datetime.datetime.fromtimestamp(t)
xcheck(today_datetime, 'today datetime')
one_day_earlier = today_datetime + one_day_earlier_delta
xcheck(one_day_earlier, 'one day earlier')
tt = today_datetime.timestamp()
xcheck(tt, 'tt')
tts = time.localtime(today_datetime.timestamp())
xcheck(tts, 'tts')
ttt = time.mktime(tts)
xcheck(ttt, 'ttt')

